package jfae.core.test.properties;

import java.util.List;
import java.util.Vector;

import jfae.core.properties.FieldInfo;
import jfae.core.properties.parsers.FieldPropertyHandler;
import jfae.core.properties.parsers.PropertyHandler;
import jfae.core.properties.parsers.annotation.AnnotationHandler;
import jfae.core.properties.parsers.annotation.ColumnHandler;
import jfae.core.properties.parsers.annotation.EditableHandler;
import jfae.core.properties.parsers.annotation.NotNullHandler;
import jfae.core.properties.parsers.annotation.PresentationHandler;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

public abstract class AbstractTestProperty {

	protected List<AnnotationHandler<?>> handlers;
	protected List<PropertyHandler<FieldInfo<?>>> phandlers;
	
	@BeforeClass
	public void initHandlers(){
		handlers = new Vector<AnnotationHandler<?>>();
		handlers.add(new ColumnHandler());
		handlers.add(new EditableHandler());
		handlers.add(new NotNullHandler());
		handlers.add(new PresentationHandler());
		
		phandlers = new Vector<PropertyHandler<FieldInfo<?>>>();
		phandlers.add(new FieldPropertyHandler(handlers));
	}
	
	@AfterClass
	public void clearHandlers(){
		handlers.clear();
	}
	
	protected FieldInfo<?> findField(List<FieldInfo<?>> fields, String fieldName){
		FieldInfo<?> field = null;
		if(fields != null){
			for (FieldInfo<?> item : fields) {
				if(fieldName.equals(item.getName())){
					field = item;
					break;
				}
			}
		}
		return field;
	}
		
}
